package com.eflow.engine.handler;


import com.eflow.engine.listener.IProcessListener;
import com.eflow.model.e.BpmConst;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Iterator;
import java.util.function.Function;

public class ProcessListenerHandler implements BpmConst {

    @Autowired
    private ObjectProvider<IProcessListener> processListeners;

    public void handle(Function<IProcessListener,Boolean> function,String id){
        Iterator<IProcessListener> iterator = processListeners.iterator();
        while(iterator.hasNext()) {
            IProcessListener next = iterator.next();
            if(PROCESS_LISTENER_TYPE.equals(next.businessType())||id.equals(next.businessType())){
                function.apply(next);
            }
        }

    }
}
